<?php

    // includes nusoap class
    require_once("nuSOAP/lib/nusoap.php");

    // Create object
    $client = new nusoap_client('http://api-sms.gate.vn/FeedBack/Service.asmx?wsdl', true);//set your dot net web service url

    $err = $client->getError();

    if ($err) {

        // error if any
        echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';

    }
	
	// init param for example 
	$MOId 		 = 38056696;
	$Telco		 = 'vina';
	$Phone		 = '84942875640';
	$ServiceNum	 = '8100';
	$Syntax		 = 'abc';
	$MessageCode = 0;
	$Message	 = 'Noi dung tin MT thu 2.';
	$PartnerCode = '8b4c3e2a-dd1d-11e1-8420-18a90565e6c8';
	$DateSend	 = date('Y-m-d\TH:i:s');
	$IsSendNow	 = true;	
	
	// begin digital sign
    $OriginalData  = $PartnerCode.$Message.$Phone;
	
    $private_key = "SMS.pem";
    $private_key_pass = "smsgatevn";
    
    if (openssl_sign($OriginalData, $Signature, array(file_get_contents($private_key), $private_key_pass)))
    {   
		$Signature = base64_encode($Signature);
    }
	
	// begin convert to Base64
	$EncryptMessage = base64_encode($Message);

    // Call method
	$result = $client->call('Send', array(
		  'MOId' 			=> $MOId
		, 'Telco' 			=> $Telco
		, 'Phone' 			=> $Phone
		, 'ServiceNum' 		=> $ServiceNum
		, 'Syntax' 			=> $Syntax
		, 'MessageCode'		=> $MessageCode
		, 'EncryptMessage' 	=> $EncryptMessage
		, 'PartnerCode' 	=> $PartnerCode
		, 'Signature' 		=> $Signature
		, 'DateSend' 		=> $DateSend
		, 'IsSendNow'		=> $IsSendNow
	));

    // fault if any
    if ($client->fault) {

        echo '<h2>Fault</h2><pre>';

        print_r($result);

        echo '</pre>';

    } else {

        // Check for errors
        $err = $client->getError();

        if ($err) {

            // Display the error
            echo '<h2>Error</h2><pre>' . $err . '</pre>';

        } else {

            // Display the result
            echo '<h2>Result</h2><pre>';

			//echo "factorial for 5 = ".$result['factorialResult'];
			echo 'Call "Send" response = '.$result['SendResult'];

            echo '</pre>';

        }

    }

    //Display the request and response
	
//	echo date("Y-m-d H:i:s");
	
?>